package Compilador;

import java.util.LinkedList;
import java_cup.runtime.*;
%%
%cupsym simbolosLienzos
%class lexicoLienzos
%standalone
%8bit
%cup
%unicode
%public
%line
%column
%char
%ignorecase
%state ESTRING
%state COMENTARIO1
%state COMENTARIO2
%eofval{

	return new Symbol(simbolosLienzos.EOF,yyline,yycolumn);
%eofval}

%{/*Crear un nuevo objeto java_cup.runtime.Symbol con información sobre el token actual sin valor*/

  private Symbol symbol(int type){
    return new Symbol(type,yyline,yycolumn);
  }
    public static int ccomentario=0;
    public static int ccadenas=0;
	
  LinkedList<NodoError> listaErrores;
  public void setListaErrores(LinkedList<NodoError> principal){
    listaErrores=principal;
  }
  LinkedList<String> ListaDeTokenInterna;
  public void setListaToken(LinkedList<String> listatoken){
    ListaDeTokenInterna=listatoken;
  }
  
 /* Crear un nuevo objeto java_cup.runtime.Symbol con información sobre el token actual con valor*/
  private Symbol symbol(int type,Object value){
    return new Symbol(type,yyline,yycolumn,value);
  }

 
 String string = "";
  
 public String HTML="<html><body>";

%}
 

/*-- MACRO DECLARACIONES --*/
id		= [a-zA-Z]([a-zA-Z]|[0-9]|"_")*
num_int		= ("-")?([0-9]+)
line_terminator	= \r|\n|\r\n
white_space    	= {line_terminator} | [ \t\f]
salto =  \n
estring		= [\"]
comilla		= ([\\])([\"])
cualquiera	= .

%%
/*-------- Sección de reglas lexicas ------ */
<YYINITIAL>{

"LienZOs"				 {System.out.println( yytext());return symbol(simbolosLienzos.tlienzos, yytext());   }			
"Fondo"			 		 {System.out.println( yytext());return symbol(simbolosLienzos.tfondo, yytext());	    }
"Red"					 {System.out.println( yytext());return symbol(simbolosLienzos.tred, yytext());		}	
"Green"					 {System.out.println( yytext());return symbol(simbolosLienzos.tgreen, yytext());		}	
"Blue"	      	   	     {System.out.println( yytext());return symbol(simbolosLienzos.tblue, yytext());		}	
"HEX:#"					 {System.out.println( yytext());return symbol(simbolosLienzos.thex, yytext());		}	
"TamANho"		 		 {System.out.println( yytext());return symbol(simbolosLienzos.ttam, yytext());		}	
"cuadro"		 		 {System.out.println( yytext());return symbol(simbolosLienzos.tcuadro, yytext());	}		
"dimeNsion"		 		 {System.out.println( yytext());return symbol(simbolosLienzos.tdimen, yytext());		}	
"Imagen" 	     		 {System.out.println( yytext());return symbol(simbolosLienzos.timg, yytext());		}
"NombrE" 		 	     {System.out.println( yytext());return symbol(simbolosLienzos.tnombre, yytext());	}	
"Tipo" 		     		 {System.out.println( yytext());return symbol(simbolosLienzos.ttipo, yytext());		}
"Colores"		 		 {System.out.println( yytext());return symbol(simbolosLienzos.tcolores, yytext());	}		
"png"                    {System.out.println( yytext());return symbol(simbolosLienzos.tpn, yytext());	}		
"jpg"                    {System.out.println( yytext());return symbol(simbolosLienzos.tjp, yytext());	}		
"gif"                    {System.out.println( yytext());return symbol(simbolosLienzos.tgi, yytext());	}		
"Pintar"				 {System.out.println( yytext());return symbol(simbolosLienzos.tpintar , yytext());    }
":P" 	         		 {System.out.println( yytext());return symbol(simbolosLienzos.tp , yytext());    }		
":N" 	         		 {System.out.println( yytext());return symbol(simbolosLienzos.tn, yytext());	    }
":G" 	         		 {System.out.println( yytext());return symbol(simbolosLienzos.tg, yytext());		}
"Vars"                   {System.out.println( yytext());return symbol(simbolosLienzos.variables, yytext());	} 
"SETvar"		 		 {System.out.println( yytext());return symbol(simbolosLienzos.tsetv, yytext());	}		
"pintar"		 		 {System.out.println( yytext());return symbol(simbolosLienzos.tPi, yytext());	}		
"Pintar:"		 		 {System.out.println( yytext());return symbol(simbolosLienzos.tpint, yytext());	}		
"var"			 	     {System.out.println( yytext());return symbol(simbolosLienzos.tvar, yytext());	}		
{id} 			 		 {System.out.println( yytext());return symbol(simbolosLienzos.tid, yytext());	}	
{num_int}		 		 {System.out.println( yytext());return symbol(simbolosLienzos.num_int, yytext());}	


"("			    		 {System.out.println( yytext());return symbol(simbolosLienzos.parentesis_i, yytext());}
")"   				   	 {System.out.println( yytext());return symbol(simbolosLienzos.parentesis_d, yytext());	}	
"," 					 {System.out.println( yytext());return symbol(simbolosLienzos.coma, yytext());		}
":" 				     {System.out.println( yytext());return symbol(simbolosLienzos.dos_puntos, yytext());	}	
"+"			    	     {System.out.println( yytext());return symbol(simbolosLienzos.plus, yytext());	}	
"-"			    		 {System.out.println( yytext());return symbol(simbolosLienzos.menos, yytext());	}		
".."					 {System.out.println( yytext());return symbol(simbolosLienzos.tpp, yytext());	}
";"						 {System.out.println( yytext());return symbol(simbolosLienzos.tpc, yytext());	}
"{"						 {System.out.println( yytext());return symbol(simbolosLienzos.abrella, yytext());	}
"}"						 {System.out.println( yytext());return symbol(simbolosLienzos.cierralla, yytext());	}
"<"			 		     {System.out.println( yytext());return symbol(simbolosLienzos.tini, yytext());	}		
">"				 		 {System.out.println( yytext());return symbol(simbolosLienzos.tfin, yytext());	}	



{estring} 				{System.out.println( yytext());ccadenas++; yybegin(ESTRING); string = "";		}

{salto}  {HTML+="<br>";}

{white_space}			{ HTML+=yytext(); }
"//"  					{ ccomentario++;HTML+=yytext();yybegin(COMENTARIO1);	}
"/*" 					{ ccomentario++; HTML+=yytext();yybegin(COMENTARIO2);	}
{cualquiera}		    { HTML+=yytext();

System.out.println(yytext());

NodoError nuevo=new NodoError();
nuevo.columna=String.valueOf(yyline);
nuevo.linea=String.valueOf(yycolumn);
nuevo.Descripcion="Error Lexico ";
nuevo.palabra=yytext();
this.listaErrores.add(nuevo);

	}


}




<ESTRING>{
{salto}         { HTML+="<br>";}
{estring} 		{ 	yybegin(YYINITIAL);
				HTML+="<font color=\"#8D4705\">"+"\""+string+"\""+"</font>"; return symbol(simbolosLienzos.estring,"\""+string+"\""); }
[ \r\t\f]		{HTML+=yytext(); System.out.println( yytext());  string += yytext();			}
{comilla}		{ System.out.println( yytext()); string += yytext();			}
{cualquiera}		{ System.out.println( yytext()); string += yytext();			}

}

<COMENTARIO1>{

{cualquiera}		{ HTML+="<font color=\"#C0C0C0\">"+yytext()+"</font>";					}
{salto}  {HTML+="<br>";string += yytext();	yybegin(YYINITIAL);	}
{line_terminator}	{string += yytext();	yybegin(YYINITIAL);		}
}

<COMENTARIO2>{
{cualquiera}		{ HTML+="<font color=\"#C0C0C0\">"+yytext()+"</font>";					}
"*/" 			    {HTML+=yytext(); string += yytext();	yybegin(YYINITIAL);		}
}


